<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>科室管理</title>
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/css/common.css"
	rel="stylesheet" />
<style type="text/css">
.main {
	margin-right: 15px;
}

ul {
	list-style: none;
}

.icon-list li a {
	cursor: pointer;
}
</style>
</head>
<body>
	<div class="main">
		<!--工具栏-->
		<div id="floatHead" class="toolbar-wrap">
			<div class="toolbar">
				<div class="box-wrap">
					<a class="menu-btn"></a>
					<div class="l-list">
						<ul class="icon-list">
							<li><a class="add" onclick="add()"><i></i><span>新增</span></a></li>
							<li><a class="all" onclick="selectAll()"><i></i><span>全选</span></a></li>
							<li><a class="del" onclick="delMore()"><i></i><span>批量删除</span></a></li>
						</ul>
					</div>
					<div class="r-list">
						<input id="search" class="keyword" /> <a
							href="javascript:void(0);" class="btn-search"
							onclick="searchItem()">查询</a>
					</div>
				</div>
			</div>
		</div>
		<!--/工具栏-->

		<table id="tt"></table>
	</div>

	<script
		src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/assets/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	var contextPath = '<%=request.getContextPath()%>';
		$(function() {
			getTableList();
			$(window).resize(function() {
				//延迟执行,防止多次触发
				setTimeout(function() {
					$('#tt').datagrid('resize');
				}, 100);
			});
		})

		/*获取数据列表*/
		function getTableList() {
			var search = $('#search').val();
			$('#tt').datagrid(
							{
								//height: $('body').height() - 270,
								nowrap : true,
								striped : true,
								collapsible : false,
								remoteSort : false,
								selectOnCheck : false,
								checkOnSelect : false,
								singleSelect : true,
								fitColumns : true,
								url : contextPath + "/bg/DT101.do?search="
										+ encodeURI(search) + "&rnd="
										+ Math.random(),
								columns : [ [
										{
											field : 'CK',
											title : '选择',
											align : 'center',
											width : 100,
											formatter : function(value, row,
													index) {
												return '<input name="check" data-code="'+row.CODE+'" type="checkbox"/>';
											}
										},
										{
											field : 'CODE',
											title : '科室编码',
											align : 'center',
											width : 100
										},
										{
											field : 'NAME',
											title : '科室名称',
											align : 'center',
											width : 100,
										},
										{
											field : 'AUTHOR',
											title : '作者',
											align : 'center',
											width : 100
										},
										{
											field : 'TITLE',
											title : '标题',
											align : 'center',
											width : 100
										},
										{
											field : 'OTHER1',
											title : '修改操作',
											align : 'center',
											width : 100,
											formatter : function(id, row, index) {
												return '<button type="button" onclick="alter(\''
												+ row.CODE
												+ '\')" class="btn">修改</button>';
											}
										},
										{
											field : 'OTHER2',
											title : '删除操作',
											align : 'center',
											width : 100,
											formatter : function(id, row, index) {
												return '<button type="button" onclick="del(\''
												+ row.CODE
												+ '\')" class="btn">删除</button>';
											}
										} ] ],
								pagination : true,
								pageSize : 10,
								pageList : [ 10, 15, 30, 40 ]
							});
		}
		//新增
		function add() {
			location.href = contextPath + "/bg/dept_introduce_edit.do?action=add&rnd="
					+ Math.random();
		}
		//修改
		function alter(code) {
			location.href = contextPath + "/bg/dept_introduce_edit.do?action=edit&code="
					+ code + "&rnd=" + Math.random();
		}
		//全选
		function selectAll() {
			var unCheck = true;
			$('input[name="check"]').each(function() {
				if (!$(this).prop('checked')) {
					$(this).prop("checked", true);
					unCheck = false;
				}
			})
			if (unCheck) {
				$('input[name="check"]').prop("checked", false);
			}
		}
		//批量删除
		function delMore() {
			var codeList = '';
			if ($('input[name="check"]:checked').size() < 1) {
				$.messager.show({title:'提示',msg:'请选择需要删除的科室！',showType:'slide'});
				return;
			}
			$('input[name="check"]:checked').each(function() {
				codeList += $(this).attr("data-code") + ",";
			})
			codeList = codeList.substring(0, codeList.length - 1);
			del(codeList);
		}
		//删除
		function del(codeList) {
			$.ajax({
				url : contextPath + "/bg/DT104.do",
				data : {
					"codeList" : codeList,
					"rnd" : Math.random()
				},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					if (data.status == 'true') {
						$.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
						getTableList();
					} else {
						$.messager.show({title:'提示',msg:'删除失败！',showType:'slide'});
					}
				}
			})
		}
		//查询
		function searchItem() {
			getTableList();
		}
	</script>
</body>
</html>